package com.lsu.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lsu.app.bean.User;
import com.lsu.app.service.LogService;
import com.lsu.app.service.UserService;
import com.lsu.app.mapper.UserMapper;

import com.lsu.app.tool.AESUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @description 针对表【user】的数据库操作Service实现
 * @Date 2023-10-16 19:31:42
 * @author hjj
 */
@Service
public class  UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService{
    private final UserMapper userMapper;

    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }


    @Override
    public Boolean isTeacher(Integer userId) {
        return userMapper.isTeacher(userId)!=0;
    }

    @Override
    public User getUserByUsername(String username) {
        return userMapper.getUserByUsername(username);
    }


    @Override
    public String getRoleByUsername(String username) {
        return userMapper.getRoleByUsername(username);
    }

    @Override
    public void setRoleByUser(Integer userId, Integer type) {
        userMapper.setRoleByUser(userId,type);
    }

    @Override
    public User getUserByUsernameType(String username, Integer type) {
        return userMapper.getUserByUsernameType(username, type);
    }

    @Override
    public Integer getIdByUsername(String username) {
        return userMapper.getIdByUsername(username);
    }

    @Override
    public String getNameById(Integer id) {
        return userMapper.getNameById(id);
    }

    @Override
    public String[] getTasteById(Integer id) {
        List<String> strs = userMapper.getTasteById(id);
        String[] tastes = new String[strs.size()];
        for (int i = 0; i < strs.size(); i++) {
            tastes[i]=strs.get(i);
        }
        return tastes;
    }

    @Override
    public List<String> getTastes() {
        return userMapper.getTastes();
    }

    @Override
    public Integer getTasteNameValueByTasteName(String tasteName) {
        Integer id = userMapper.getTasteNameValueByTasteName(tasteName);
        return id!=null?id:16;
    }

    @Override
    public List<Integer> getIdsByName(String name) {
        List<Integer> ids = userMapper.getIdsByName(name);
        List<Integer> returnIds = new ArrayList<>();
        for (Integer id : ids) {
            if(userMapper.isTeacher(id)!=0){
                returnIds.add(id);
            }
        }
        return returnIds;
    }
}




